package com.cn.pack.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
public class ModifyRequestEntityFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return FilterConstants.PRE_DECORATION_FILTER_ORDER + 1;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        try {
            RequestContext context = RequestContext.getCurrentContext();
            Map<String, List<String>> queryParams = context.getRequestQueryParams();
            queryParams = (queryParams == null ? new HashMap<>() : queryParams);
            List<String> list = new ArrayList<>();
            list.add("9527");
            queryParams.put("cardNum", list);
            context.setRequestQueryParams(queryParams);
        } catch (Exception e) {
            System.out.println("***************** error = " + e.toString());
        }
        return null;
    }
}
